#include <iostream>
#include <Rectangle.h>
using namespace std;

namespace commonSw 
{
   int isUnvaild(double val_i, double maxVal_i, double minVal_i)
   {
     return ((val_i <= minVal_i) || (val_i > maxVal_i)) ? 1 : 0;
   }

   double getPrecision(double val_i)
   {
     return ((double)((int)(val_i*100)))/100;
   }

   double getRound(double val_i)
   {
     return ((double)((int)(val_i*100+0.5)))/100;
   }
}

Shape::~Shape()
{}

using namespace commonSw;

Rectangle::Rectangle(double length, double width):length_m(getPrecision(length)),width_m(getPrecision(width))
{
   if(isUnvaild(length_m, max_length, min_length) || isUnvaild(width_m, max_width, min_width))
      length_m = width_m = 0;
}

Rectangle::~Rectangle()
{}

double  Rectangle::calcArea() const
{
    return getRound(length_m*width_m);
}

double Rectangle::calcPerimeter() const
{
   return (length_m+width_m)*2;
}

Square::Square(double line):line_m(getPrecision(line))
{
   if(isUnvaild(line_m, max_line, min_line) )
      line_m = 0;
}

Square::~Square()
{}

double  Square::calcArea() const
{
    return getRound(line_m*line_m);
}

double Square::calcPerimeter() const
{
   return line_m*4;
}

